package com.itheima.reggie.demo;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.dysmsapi.model.v20170525.*;


public class SendSms {

    public static void main(String[] args) {

        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t8MvjNaAEHEEFzMHpBF", "ykAHG3dNsnwjqcvvwrNUETtvOsexj2");
        /** use STS Token
        DefaultProfile profile = DefaultProfile.getProfile(
            "<your-region-id>",           // The region ID
            "<your-access-key-id>",       // The AccessKey ID of the RAM account
            "<your-access-key-secret>",   // The AccessKey Secret of the RAM account
            "<your-sts-token>");          // STS Token
        **/

        // 创建客户端对象
        IAcsClient client = new DefaultAcsClient(profile);


        // 创建发送对象
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers("13291840116");
        request.setSignName("日拱一卒");
        request.setTemplateCode("SMS_243190674");
        request.setTemplateParam("{\"code\": \"1234\"}");


        try {
            // 发送，并获取响应的结果
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}
